package com.xbongbong.saas.script.tempenum;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.ComboTypeEnum;
import com.xbongbong.paas.enums.DateTimeEnum;
import com.xbongbong.paas.help.FormDataFormExplainHelper;
import com.xbongbong.paas.field.DefaultAttrPoJo;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.ItemPoJo;
import com.xbongbong.paas.field.LimitChooseRangePoJo;
import com.xbongbong.paas.field.LinkDetailPojo;
import com.xbongbong.paas.field.SerialNumberPoJo;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.enums.ForbiddenSettingEnum;
import com.xbongbong.saas.enums.OutstockTypeEnum;
import com.xbongbong.saas.enums.ShowTypeEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.OutstockEnum;
import com.xbongbong.saas.script.help.InitExplainsHelper;
import com.xbongbong.sys.enums.RoleEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * 出库单
 *
 * @author Jian.Wang
 * @version v1.0
 * @date 2019/1/19
 * @since v1.0
 */
@Getter
public enum TempOutstockEnum {
    //
    BASE_INFO(OutstockEnum.BASE_INFO),
    SHEET_NO(OutstockEnum.SHEET_NO),
    TIME(OutstockEnum.TIME),
    TYPE(OutstockEnum.TYPE),
    REF_ID(OutstockEnum.REF_ID),
    WAREHOUSE_ID(OutstockEnum.WAREHOUSE_ID),
    PRODUCT_INFO(OutstockEnum.PRODUCT_INFO),
    PRODUCT(OutstockEnum.PRODUCT),
    EXTENSION_INFO(OutstockEnum.EXTENSION_INFO),
    EXPRESS_NAME(OutstockEnum.EXPRESS_NAME),
    EXPRESS_NO(OutstockEnum.EXPRESS_NO),
    MANAGER_ID(OutstockEnum.MANAGER_ID),
    MEMO(OutstockEnum.MEMO),
    SYSTEM_INFO(OutstockEnum.SYSTEM_INFO),
    CREATOR_ID(OutstockEnum.CREATOR_ID),
    ADD_TIME(OutstockEnum.ADD_TIME),
    UPDATE_TIME(OutstockEnum.UPDATE_TIME),


    OUTBOUND(OutstockEnum.OUTBOUND),
    WAREHOUSE_ID_LINKED_TEXT(OutstockEnum.WAREHOUSE_ID_LINKED_TEXT),
    REF_ID_LINKED_TEXT(OutstockEnum.REF_ID_LINKED_TEXT),
    ;
    private OutstockEnum anEnum;

    TempOutstockEnum(OutstockEnum outstockEnum) {
        this.anEnum = outstockEnum;
    }
    public static List<TempOutstockEnum> getAllEnum() {
        java.util.List<TempOutstockEnum> list = new ArrayList<>();
        Collections.addAll(list, values());
        return list;
    }

    // ===================================模板字段初始化======================================

    /**
     * 初始化编号
     * @param fieldAttrEntity
     */
    public static void initSheetNo(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setAttrName(OutstockEnum.SHEET_NO.getAttrName());
        fieldAttrEntity.setDefaultName(OutstockEnum.SHEET_NO.getAttrName());

        LinkDetailPojo linkDetailPojo = new LinkDetailPojo();
        linkDetailPojo.setBusinessType(XbbRefTypeEnum.OUTSTOCK.getCode());
        linkDetailPojo.setSubBuisenssType(XbbRefTypeEnum.OUTSTOCK.getCode());
        linkDetailPojo.setSaasMark(SaasMarkEnum.SAAS.getCode());
        linkDetailPojo.setAttr(SHEET_NO.getAnEnum().getAttr());
        fieldAttrEntity.setLinkDetail(linkDetailPojo);
        // 不能重复
        fieldAttrEntity.setNoRepeat(1);
        // 默认的编号规则
        SerialNumberPoJo serialNumberPoJo = InitExplainsHelper.setSerialNumber(SerialNumberEnum.QT_OUTSTOCK_NO);
        fieldAttrEntity.setSerialNumber(serialNumberPoJo);
        fieldAttrEntity.setIsForbidden(0);
    }

    /**
     * 初始化出库类型
     *
     * @param fieldAttrEntity
     * @author chaoxiong.lei
     * @Date 11:01 2019/1/18
     * @since
     **/
    public static void initType(FieldAttrEntity fieldAttrEntity) {
        // 将出库类型设置为下拉选项
        //Map<Integer, String> instockTypeMap = InstockTypeEnum.getOtherInstockTypeMap();
        List<ItemPoJo> itemPoJos = InitExplainsHelper.setCombItemByEnum(OutstockTypeEnum.class, fieldAttrEntity.getFieldType());
        List<String> otherOutstockCodeList = Arrays.asList(OutstockTypeEnum.INVENTORY_OUTSTOCK.getName(),
                OutstockTypeEnum.TRANSFER_OUTSTOCK.getName(), OutstockTypeEnum.OTHER_OUTSTOCK.getName(),
                OutstockTypeEnum.ASSEMBLE_OUTSTOCK.getName());
        for (ItemPoJo itemPoJo: itemPoJos) {
            itemPoJo.setNoDel(1);
            itemPoJo.setNoEdit(1);
            if (!otherOutstockCodeList.contains(itemPoJo.getText())) {
                itemPoJo.setShowType(ShowTypeEnum.NONE.getCode());
                itemPoJo.setEditHide(1);
            } else {
                if (Objects.equals(itemPoJo.getText(), OutstockTypeEnum.OTHER_OUTSTOCK.getName())) {
                    itemPoJo.setChecked(true);
                } else {
                    itemPoJo.setFieldMap(Arrays.asList(OutstockEnum.REF_ID.getAttr()));
                    itemPoJo.setShowType(ShowTypeEnum.EXCLUDE_NEW.getCode());
                }
            }
        }
        fieldAttrEntity.setItemBanDefault(1);
        fieldAttrEntity.setItems(itemPoJos);
        fieldAttrEntity.setEditable(0);
        // fieldAttrEntity.setItems(InitExplainsHelper.setCombItem(instockTypeMap));
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setShowEditable(0);
    }

    /**
     * 初始化日期
     *
     * @param fieldAttrEntity
     */
    public static void initTime(FieldAttrEntity fieldAttrEntity) {
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        defaultAttrPoJo.setDefaultType("today");
        fieldAttrEntity.setDateType(DateTimeEnum.TIME.getType());
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
        fieldAttrEntity.setIsForbidden(0);
    }

    /**
     * 初始化出库仓库
     * 将关联显示的字段设置到出库仓库字段中
     *
     * @param fieldAttrEntity
     * @author chaoxiong.lei
     * @Date 11:01 2019/1/18
     * @since
     **/
    public static void initWarehouseId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedText(OutstockEnum.WAREHOUSE_ID_LINKED_TEXT.getAttr());
        fieldAttrEntity.setLinkedType(XbbRefTypeEnum.WAREHOUSE.getCode());
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setEditable(1);
    }

    /**
     * 初始化负责人字段
     * 将关联显示的字段设置到该字段中
     *
     * @param fieldAttrEntity
     * @author chaoxiong.lei
     * @Date 11:01 2019/1/18
     * @since
     **/
    public static void initManagerId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setMultiple(0);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setRequired(1);
        fieldAttrEntity.setShowEditable(0);
        fieldAttrEntity.setAdd(1);
        fieldAttrEntity.setAddAdvanceEnable(1);
        fieldAttrEntity.setShowAdd(1);
        fieldAttrEntity.setRemove(1);
        fieldAttrEntity.setRemoveAdvanceEnable(1);
        fieldAttrEntity.setShowRemove(1);
        // 默认的查询范围
        LimitChooseRangePoJo limitChooseRangePoJo = new LimitChooseRangePoJo();
        fieldAttrEntity.setLimitChooseRange(limitChooseRangePoJo);
        fieldAttrEntity.setAddRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.WAREHOUSE_MANAGER));
        fieldAttrEntity.setRemoveRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.WAREHOUSE_MANAGER));
    }

    /**
     * 初始化关联单据字段
     * 将关联显示的字段设置到该字段中
     *
     * @param fieldAttrEntity
     * @author chaoxiong.lei
     * @Date 11:01 2019/1/18
     * @since
     **/
    public static void initRefId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedText(OutstockEnum.REF_ID_LINKED_TEXT.getAttr());
        fieldAttrEntity.setIsMultiBusiness(1);
        fieldAttrEntity.setBusinessType(XbbRefTypeEnum.OUTSTOCK.getCode());
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setShowEditable(0);

        List<String> settingList = Arrays.asList(ForbiddenSettingEnum.DISABLE_VISIBLE_CORRELATION_FIELD.getAlias());
        fieldAttrEntity.setForbiddenSettingList(settingList);
    }


    /**
     * 物流公司
     */
    public static void initExpressNo(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setComboType(ComboTypeEnum.CUSTOM.getType());
        fieldAttrEntity.setDictionaryFlag(0);
        fieldAttrEntity.setIsDictionary(1);
    }

    public static void initCreatorId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }

    public static void initAddTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
    public static void initUpdateTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
    public static void initProducts(FieldAttrEntity fieldAttrEntity){
        fieldAttrEntity.setIsForbidden(0);
    }
}
